package com.example.printservice.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 访问接口检查
 */
@Slf4j
public class AllIntercepotor implements HandlerInterceptor {

    /***
     * 目标方法执行之前
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String referer = request.getHeader("referer"); //获取referer
        if(referer==null) //判断是否为空
        {
            throw new Exception("请使用指定网址进行调用");
        }
        else if (referer.equals("http://116.63.169.130/")||referer.equals("http://10.13.117.48/")||referer.equals("http://localhost:8081/")) //否者再进行判断是否是我们指定的网址  如果是 就放行
        {
            return true;
        }else {
            log.error(referer+"不正确，没有使用指定路径上传");
            return false;
        }


//        return true;
    }
}
